//
//  TTDianpuOrderManagerViewController.m
//  TaoTuo
//
//  Created by admin on 2019/11/11.
//  Copyright © 2019 admin. All rights reserved.
//

#import "TTDianpuOrderManagerViewController.h"
#import <JXCategoryTitleView.h>
#import <JXCategoryIndicatorLineView.h>
#import <JXCategoryListContainerView.h>
#import "TTDianpuOrderPageViewController.h"
#import "UIViewController+LLPanBack.h"

@interface TTDianpuOrderManagerViewController ()<JXCategoryViewDelegate, JXCategoryListContainerViewDelegate>

@property (nonatomic, strong) JXCategoryTitleView *categoryView;
@property (nonatomic, strong) JXCategoryListContainerView *listContainerView;
@property (nonatomic, strong) NSArray *titles;
@property (nonatomic, assign) NSInteger defaultIndex;   // 默认选中的index

@end

@implementation TTDianpuOrderManagerViewController


- (instancetype)initWithDefaultIndex:(NSInteger)defaultIndex
{
    self = [super init];
    if (self) {
        self.defaultIndex = defaultIndex;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"订单管理";
    // 初始化JXCategoryTitleView
    self.titles = @[@"待下单", @"待完成", @"已完成", @"全部"];
    self.categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, 50)];
    self.categoryView.delegate = self;
    self.categoryView.titleColor = UIColorHex(333333);
    self.categoryView.titleSelectedColor = UIColorHex(333333);
    self.categoryView.titles = self.titles;
    self.categoryView.titleColorGradientEnabled = YES;
    self.categoryView.contentEdgeInsetLeft = 24;        // 左边距
    self.categoryView.contentEdgeInsetRight = 24;       // 右边距
    [self.view addSubview:self.categoryView];
    
    // 添加指示器
    JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
    lineView.indicatorColor = UIColorHex(9B71FF);
    lineView.indicatorHeight = 8;
    lineView.verticalMargin = 14;
    lineView.indicatorCornerRadius = 4;
    self.categoryView.indicators = @[lineView];
    
    
    // 初始化JXCategoryListContainerView并关联到categoryView
    
    self.listContainerView = [[JXCategoryListContainerView alloc] initWithDelegate:self];
    self.listContainerView.frame = CGRectMake(0, 50, SCREEN_WIDTH, SCREEN_HEIGHT - StatusBarAndNavBar_Height - 50 - self.bottomSpace);
    [self.view addSubview:self.listContainerView];
    //关联到categoryView
    self.categoryView.contentScrollView = self.listContainerView.scrollView;
    
    self.categoryView.defaultSelectedIndex = self.defaultIndex;
    self.listContainerView.defaultSelectedIndex = self.defaultIndex;
    // 支持侧滑返回
    [self addPanGestureRecognizerToView:self.listContainerView.scrollView];
    
}

#pragma mark - JXCategoryViewDelegate
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
//    NSLog(@"--> %ld", (long)index);

}

- (void)categoryView:(JXCategoryBaseView *)categoryView didScrollSelectedItemAtIndex:(NSInteger)index {
//    NSLog(@"%@", NSStringFromSelector(_cmd));
}

- (void)categoryView:(JXCategoryBaseView *)categoryView didClickSelectedItemAtIndex:(NSInteger)index {
    [self.listContainerView didClickSelectedItemAtIndex:index];
}

- (void)categoryView:(JXCategoryBaseView *)categoryView scrollingFromLeftIndex:(NSInteger)leftIndex toRightIndex:(NSInteger)rightIndex ratio:(CGFloat)ratio {
    [self.listContainerView scrollingFromLeftIndex:leftIndex toRightIndex:rightIndex ratio:ratio selectedIndex:categoryView.selectedIndex];
}



#pragma mark - JXCategoryListContainerViewDelegate
- (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index {
    
//    NSString *indexStr = [NSString stringWithFormat:@"%ld", index];
//    int status = [self.statusDic[indexStr] intValue];
//    TTWaitConfirmViewController *waitVC = [[TTWaitConfirmViewController alloc] initWithStatus:status];
//    return waitVC;
    TTDianpuOrderPageViewController *orderPageVC = [[TTDianpuOrderPageViewController alloc] initWithStatus:index];
    return orderPageVC;
    
}

- (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView {
    return self.titles.count;
}


- (UIView *)listView
{
    return self.view;
}




@end
